package wrapper

import (
	"context"
	"github.com/asim/go-micro/v3/server"
	"emicro_test/emicro_9/grpc_server/user/common"
	"github.com/go-micro/plugins/v3/wrapper/trace/opentracing"
	"log"
)


//服务端装饰器
func ServerWrapper() server.HandlerWrapper{
	return func(h server.HandlerFunc) server.HandlerFunc {
		return func(ctx context.Context, req server.Request, rsp interface{}) error {
			log.Println("Server wrapper!!!")
			return h(ctx, req, rsp)
		}
	}
}

//分布式链路追踪
func ServerTrace(service *common.EmicroService) server.HandlerWrapper{
	tracer := GetTracer(common.ServerName, service.Addr, common.Config)
	tracerHandler := opentracing.NewHandlerWrapper(tracer)
	return tracerHandler
}